<?php
require_once '../../commonutils/util/PageTemplate.php';
require_once '../../commonutils/db/DBConnectionManager.php';

function listProgramsAndSemester($webPage){
	
	$webPage->addContent("<form name='selectForm' method='post'>");
	$webPage->addContent("<table align = 'center' border=1 name='listTable'>");
	$webPage->addContent("<tr><th>Program:</th>");
	$webPage->addContent("<td><select size=1 name=selectProgramCode>");
		$result = DBConnectionManager::query("select programCode, longName from Program order by longName");
			
		while($row = mysql_fetch_assoc($result)){
			$longName = $row['longName'];
			$programCode = $row['programCode']; 
			$webPage->addContent("<option value=$programCode>$longName</option>");	
		}
	$webPage->addContent("</select></td></tr>");
	$webPage->addContent("<tr><th>Semester:</th>");
	$webPage->addContent("<td><select size=1 name=selectSemesterID>");
		$result = DBConnectionManager::query("select * from Semester order by year, term");
			
		while($row = mysql_fetch_assoc($result)){
			$semesterID = $row['semesterID'];
			$year = $row['year'];
			$term = $row['term']; 
			$webPage->addContent("<option value=$semesterID>$year-$term</option>");	
		}
	$webPage->addContent("</select></td></tr>");
	$webPage->addContent("<tr><td colspan=2 align=center>");
	$webPage->addContent("<input type=submit value='OK' name=submitOK></input>");
	$webPage->addContent("<input type=reset value='Reset' name=reset></input>");
	$webPage->addContent("</td></tr>");
	$webPage->addContent("</table></form>");
}

function setSessionParameters(){
	$_SESSION["programCode"] = $_POST['selectProgramCode'];
	$_SESSION["semesterID"] = $_POST['selectSemesterID'];
}

$webPage = new Page();

$webPage->addHeader('Select Program And Semester');

if(isset($_POST['submitOK'])){
	setSessionParameters();
}else{
	listProgramsAndSemester($webPage);	
}
	
$webPage->addFooter(date('Y'), 'IIPIS');
echo $webPage->get();

?>